/**
 * Copyright (c) 2015-2019, Golly Hu 胡高 (3722711@qq.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.hg.jfsa.manage.controller.module.column.validator;

import com.jfinal.core.Controller;

import cn.hg.base.jfinal.validator.BaseValidator;

/**
 * @author Golly
 */
public class ColumnValidator extends BaseValidator {

	@Override
	protected void handleError (Controller c) {}

	@Override
	protected void validate (Controller c) {
		this.validateRequired("column.name", "nameMsg", "名称为必填！");
		this.validateRequired("column.url", "urlMsg", "链接地址为必填！");
		this.validateRequired("column.type", "typeMsg", "显示方式为必填！");
		this.validateRequired("column.sortNum", "sortNumMsg", "排序号为必填！");
		this.validateRequired("column.urlType", "urlTypeMsg", "链接类型为必填！");

		if ("outer".equals(c.get("column.urlType"))) {
			this.validateUrl("column.url", "urlMsg", "外部链接格式无效，必须以“http://”或“https://”开头！");
		} else {

			if (!c.get("column.url").startsWith("/")) {
				this.addError("urlMsg", "内部链接必须以“/”开头！");
			}

		}

	}

}
